/**
* 版权声明：厦门睿商网络科技有限公司 版权所有 违者必究
* 日    期：2020-04-07
*/
package com.rzico.basics.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.rzico.annotation.Log;
import com.rzico.base.BaseController;
import com.rzico.base.CommResult;
import com.rzico.basics.entity.Enterprise;
import com.rzico.basics.entity.Vip;
import com.rzico.basics.service.EnterpriseService;
import com.rzico.basics.service.VipService;
import com.rzico.entity.PageResult;
import com.rzico.entity.Pageable;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 会员等级控制层
 *
 * @author Rzico Boot
 * @version 1.0
 * @date 2020-04-07
 */
@Api(description = "会员等级接口")
@RestController
@RequestMapping("/vip")
public class VipController extends BaseController {

    @Autowired
    private VipService vipService;

    @Autowired
    private EnterpriseService enterpriseService;

    /**
     * 分页查询会员等级
     *
     * @return
    */
    @ApiOperation("分页查询会员等级")
    @GetMapping("/list")
    public CommResult<Vip> list(String mchId, Pageable pageable) {
        Map<String, Object> params = new HashMap<String, Object>();
        params = buildSortField(params, pageable);
        params.put("sortField","vip");
        params.put("sortType","asc");

        Enterprise enterprise = enterpriseService.findByMch(mchId);

        params.put("enterpriseId", enterprise.getId());


        Page<Object> startPage = PageHelper.startPage(pageable.getPageNum(), pageable.getPageSize());
        List<Vip> list = vipService.selectList(params);
        PageResult<Vip> pageResult = new PageResult<Vip>(list, startPage.getTotal(), pageable);
        return CommResult.success(pageResult);
    }

}
